// pages/refund_all/refund_all.js
var app = getApp();
var ApiUrl = app.globalData.ApiUrl; 
var key = "";    
Page({
  /**
   * 页面的初始数据
   */
  data: {
  
  },
  onLoad: function (options) {    
      key = options.key;
      var order_id = options.order_id;
      var that = this;
      wx.request({
        url: ApiUrl+'/index.php?act=member_refund&op=refund_all_form' ,
        data: {"key":key, "order_id":order_id},
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'get',
        success:function(result){
           
          that.setData({
            order:result.data.datas.order,
            goods_list: result.data.datas.goods_list,
            gift_list: result.data.datas.gift_list,
            key: key,
            order_id: order_id
          });
        }
      }); 
  },
  chooseImage:function(options){    
      var filekey = options.currentTarget.dataset.filekey;
      var that = this;    
      wx.chooseImage({
        count: 3,
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function (res) {
            // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
            var tempFilePaths = res.tempFilePaths;
            wx.uploadFile({
              url:ApiUrl+"index.php?act=member_refund&op=upload_pic",
              filePath: tempFilePaths[0],
              name:'refund_pic',           
              formData: {
                'key': key,               
              },
              success: function (result) { 
                var datas = JSON.parse(result.data);   
                  
                var picname = new Array();
                var file_name = new Array();
                picname[filekey] = datas.datas.pic;
                file_name[filekey] = datas.datas.file_name               
                that.setData({
                  pic: picname,
                  file_name:file_name
                });              
              }
            })            
        }

      });
  },
  formSubmit:function(params){
  
    var that = this;
    var param = {};
    param = params.detail.value;
    
    param.key = that.data.key;
    param.order_id = that.data.order_id;
     
    if(!param.buyer_message){
      wx.showToast({
        title: '请填写退款说明',
        icon: "loading",
        mask:true,
        duration: 1000,
      });
      return false;
    } else if (!param.iamgeV){
      wx.showToast({
        title: '请上传至少一张图片',
        icon: "loading",
        mask: true,
        duration: 1000,
      });
      return false;
    }else{
      wx.request({
        url: ApiUrl + '/index.php?act=member_refund&op=refund_all_post',
        data: param,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'post',
        success: function (result) {          
          wx.reLaunch({
            url: '/pages/order/order',
          })  
        },
        fail:function(res){
          wx.showModal({
            title: '网络错误',
            content: '请稍后重试',
          })
        }
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})